﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Threading.Tasks;
using System.Data.SqlClient;
using DAL;

namespace BLL
{
    public class ForReaderUpdate
    {
        public SqlDataReader FindReader(string ReaderID)
        {
            //查询语句
            StringBuilder sb = new StringBuilder();            
            //管理员登录
            if (StaticStore.loginType == true)
            {
                sb.Length = 0;
                sb.AppendFormat(@"select ReaderName,Pwd,Phone,Address,IDCard from Reader where ReaderID = '{0}'"
                            , Convert.ToString(ReaderID));
            }
            else //读者登录
            {
                sb.Length = 0;
                sb.AppendFormat(@"select ReaderName,Pwd,Phone,Address,IDCard from Reader where ReaderID = '{0}'"
                            , Convert.ToString(StaticStore.readerID));
            }
            //执行查询
            SqlDataReader reader = DBHelper.ExecuteReader(sb.ToString());
            return reader;
        }
        public bool UpdateReader(string ReaderName,string Pwd,string Phone,string Address,string IDCard,string ReaderID)
        {
            //默认修改失败
            bool valid = false;
            string sql = string.Format(@"update Reader set ReaderName = '{0}',Pwd = '{1}',Phone = '{2}',Address = '{3}',IDCard = '{4}'
                         where ReaderID = {5}",ReaderName,Pwd,Phone,Address,IDCard,ReaderID);
            //执行修改
            int iRet = DBHelper.ExecuteNonQuery(sql);
            if (iRet == 1)
            {
                valid = true;
            }
            return valid;
        }
    }
}
